const getChunks = (modulesContext) => {
    if (!modulesContext || modulesContext.length === 0) {
        return undefined;
    }
    return modulesContext.keys().reduce((modules, key) => {
        modules[key.replace(/(^\.\/)|(\.js$)/g, '')] = modulesContext(key).default
        return modules;
    }, {});
}

let constants = {};

const apiContext = require.context('./modules', true, /\.js$/);
const apiChunks = getChunks(apiContext);

Object.keys(apiChunks).forEach(item => {
    let chunk = apiChunks[item];
    Object.keys(chunk).forEach(key => {
        constants[key] = chunk[key];
    });
});

export default constants;
